﻿#include "stdafx.h"
#include "Druid_Restoration.h"
#include "PressKeyUtil.h"
#include "DefInfo/GameInfo.h"
#include "DefInfo/Team_Raid_Info.h"

DruidRestoration::DruidRestoration()
{
	IRoutine::spec_id = Restoration;
	action.Init();
}

DruidRestoration::~DruidRestoration()
{

}

void DruidRestoration::ChooseBattleAction()
{
	if (PressKeyUtil::inst().press_battle_enbale)
	{
		do
		{
			Team_Raid_Info& target = GameInfo::inst().GetTarget();
			//double test_di = target.GetDistance();

			RoutineAction::VecLostHp vec_hp;
			std::string heal_target = action.ChooseHealTarget(vec_hp);
			bool do_action = false;
			if (last_heal_target != ""&& heal_target != last_heal_target)
			{
				if (GameInfo::inst().IsTarget(last_heal_target))
				{
					do_action = true;
				}
				else
				{
					last_heal_target = "";
				}
			}
			if (GameInfo::inst().IsTarget(heal_target))
			{
				do_action = true;
			}
			if (do_action)
			{
				last_heal_target = heal_target;
				if (vec_hp.size() > 0)
				{
					DoHealAction(vec_hp);
				}
			}
			else if (heal_target != "") {
				action.ChangeTarget(heal_target);
			}

		} while (false);
	}
}


void DruidRestoration::DoHealAction(RoutineAction::VecLostHp& vec_hps)
{
	if (GameInfo::inst().IsPlayer_Channel_or_Casting())
	{
		return;
	}

	PressKeyUtil::inst().StartLock();
	Team_Raid_Info& target = GameInfo::inst().GetTarget();
	if (!target.IsDeadOrGhost())
	{
		int first_lost_hp = vec_hps[vec_hps.size() - 1].lost_hp;
		// 有免费愈合,就用免费愈合

		// 先用回春术

		if (GameInfo::inst().CheckSpellCanUse(Rejuvenation) && SatisfySpellCondition("回春术", target))
		{
			if (target.buff(Rejuvenation).Down())
			{
				PressKeyUtil::inst().SendKeyBySpellID(Rejuvenation);
			}
			if ((target.buff(Rejuvenation).Up() && target.buff(Rejuvenation).duration <= 40))
			{
				PressKeyUtil::inst().SendKeyBySpellID(Rejuvenation);
			}
		}
		// 先用免费愈合

		if (GameInfo::inst().GetPlayer().buff(Clearcasting).Up() && SatisfySpellCondition("有buff 愈合", target))
		{
			if (GameInfo::inst().CheckSpellCanUse(Regrowth))
			{
				if (target.buff(Regrowth).Down())
				{
					PressKeyUtil::inst().SendKeyBySpellID(Regrowth);
				}
			}
		}
		// 生命绽放.
		Team_Raid_Info* spell_target = GameInfo::inst().SpellByPlayer(Lifebloom);
		if (spell_target == nullptr)
		{
			if (GameInfo::inst().CheckSpellCanUse(Lifebloom) && SatisfySpellCondition("生命绽放", target))
			{
				PressKeyUtil::inst().SendKeyBySpellID(Lifebloom);
			}
		}
		// 塞纳里奥结界
		if (GameInfo::inst().CheckSpellCanUse(Cenarion_Ward) && SatisfySpellCondition("塞纳里奥结界", target))
		{
			if (target.buff(Cenarion_Ward).Down() && target.buff(Cenarion_Ward_2).Down())
			{
				PressKeyUtil::inst().SendKeyBySpellID(Cenarion_Ward);
			}
		}
		// 愈合
		if (GameInfo::inst().CheckSpellCanUse(Regrowth) && SatisfySpellCondition("无buff 愈合", target))
		{
			if (target.buff(Regrowth).Down())
			{
				PressKeyUtil::inst().SendKeyBySpellID(Regrowth);
			}
		}

		// 野性生长
		if (vec_hps.size() > 3)
		{
			Team_Raid_Info* spell_target = GameInfo::inst().SpellByPlayer(Wild_Growth);
			if (spell_target == nullptr)
			{
				if (GameInfo::inst().CheckSpellCanUse(Wild_Growth) && SatisfySpellCondition("野性生长", target))
				{
					PressKeyUtil::inst().SendKeyBySpellID(Wild_Growth);
				}
			}
		}

		// 迅捷治愈
		if (GameInfo::inst().CheckSpellCanUse(Swiftmend) && SatisfySpellCondition("迅捷治愈", target))
		{
			PressKeyUtil::inst().SendKeyBySpellID(Swiftmend);
		}

		// 铁木树皮
		if (GameInfo::inst().CheckSpellCanUse(Ironbark))
		{
			if (GameInfo::inst().GetTarget().GetUnitRole() == GRT_Tank && SatisfySpellCondition("铁木树皮-坦克", target))
			{
				PressKeyUtil::inst().SendKeyBySpellID(Ironbark);
			}
			if (GameInfo::inst().IsInParty() || GameInfo::inst().IsInRaid())
			{
				if (GameInfo::inst().GetTarget().GetUnitRole() == GRT_Healer && GameInfo::inst().GetIsPlayerIsTarget() && SatisfySpellCondition("铁木树皮-自己", target))
				{
					PressKeyUtil::inst().SendKeyBySpellID(Ironbark);
				}
			}
			else
			{
				if (GameInfo::inst().GetIsPlayerIsTarget() && SatisfySpellCondition("铁木树皮-自己", target))
				{
					PressKeyUtil::inst().SendKeyBySpellID(Ironbark);
				}
			}

		}

		// 血线低于40% 直接读一个愈合
		if (GameInfo::inst().CheckSpellCanUse(Regrowth) && SatisfySpellCondition("最低血量愈合", target))
		{
			PressKeyUtil::inst().SendKeyBySpellID(Regrowth);
		}
	}
	// 如果死了.在战斗中直接战复, 如果非战斗读起死回生
	else
	{
		if (GameInfo::inst().PlayerInBattle())
		{
			if (GameInfo::inst().CheckSpellCanUse(Rebirth))
			{
				PressKeyUtil::inst().SendKeyBySpellID(Rebirth);
			}
		}
		else
		{
			if (GameInfo::inst().CheckSpellCanUse(Revive))
			{
				PressKeyUtil::inst().SendKeyBySpellID(Revive);
			}
		}
	}

	PressKeyUtil::inst().EndLock();
}